class BookmarkModel {
  final String userId;
  final String postId;
  final DateTime createdAt;

  BookmarkModel({
    required this.userId,
    required this.postId,
    required this.createdAt,
  });

  factory BookmarkModel.fromJson(Map<String, dynamic> json) {
    return BookmarkModel(
      userId: json['user_id']?.toString() ?? '',
      postId: json['post_id']?.toString() ?? '',
      createdAt:
          json['created_at'] != null
              ? DateTime.parse(json['created_at'].toString())
              : DateTime.now(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'user_id': userId,
      'post_id': postId,
      'created_at': createdAt.toIso8601String(),
    };
  }

  BookmarkModel copyWith({
    String? userId,
    String? postId,
    DateTime? createdAt,
  }) {
    return BookmarkModel(
      userId: userId ?? this.userId,
      postId: postId ?? this.postId,
      createdAt: createdAt ?? this.createdAt,
    );
  }

  // 生成唯一ID（组合键）
  String get id => '${userId}_$postId';
}
